#!/usr/bin/python3
# -*- coding:utf-8 -*-
# @Time   :2021/1/26
# @Author :CJX
# @File   :kill_all.py

import os
import re
import signal


# execute command, and return the information. 执行命令并返回命令输出信息
def execCmd(cmd):
    r = os.popen(cmd)
    text = r.read()
    r.close()
    return text


def doSomething():
    os.system('nohup python3 /home/pi/ph/main.py >/dev/null  2>&1 &')


def stopChild():
    processInfo = os.popen("ps -ef|grep main.py|grep -v grep|awk '{print $2}'").readlines()
    for pid in processInfo:
        os.kill(int(pid), signal.SIGKILL)


# stop parent
def stopParent():
    parentList = os.popen("ps -ef|grep main.py|grep -v grep|awk '{print $2}'").readlines()
    for pid in parentList:
        os.kill(int(pid), signal.SIGKILL)
        
def i2cstopChild():
    processInfo = os.popen("ps -ef|grep i2c_sql.py|grep -v grep|awk '{print $2}'").readlines()
    for pid in processInfo:
        os.kill(int(pid), signal.SIGKILL)


# stop parent
def i2cstopParent():
    parentList = os.popen("ps -ef|grep i2c_sql.py|grep -v grep|awk '{print $2}'").readlines()
    for pid in parentList:
        os.kill(int(pid), signal.SIGKILL)

def stopAll():
    stopChild()
    stopParent()
    i2cstopChild()
    i2cstopParent()

if __name__ == '__main__':
    stopAll()
